<template>
    <div class="container">
      <div class="container-title">
        <p>优惠券使用</p>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item>社区生活</el-breadcrumb-item>
          <el-breadcrumb-item>消费优惠券</el-breadcrumb-item>
          <el-breadcrumb-item>优惠券使用</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="search-box">
      <el-form ref="form" :model="form">
        <el-form-item>
          <!-- 查询框 -->
            <el-input v-model="couponName" placeholder="优惠券名称"></el-input>

            <el-input v-model="phone" placeholder="联系方式"></el-input>
        </el-form-item>
        <el-form-item>
          
          <el-button
            type="success"
            @click="onSearch"
            icon="el-icon-search"
            style="background-color: #0bb197" 
            class="refer"
            >查询</el-button
          ><el-button @click="onReset" icon="el-icon-refresh" class="reset"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    
        <!-- 表格 -->
        <div class="data-list">
          <div class="data-list-title">
            <span>查询结果列表</span>
            <el-button type="success" style="background-color: #0bb197"
              >导出</el-button
            >
        </div>
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="cuId" label="序号" width="180" align="center"></el-table-column>
          <el-table-column prop="couponManagement.cmId" label="优惠券ID" width="180" align="center"></el-table-column>
          <el-table-column prop="couponManagement.couponName" label="优惠券名称" width="180" align="center"></el-table-column>
          <el-table-column prop="couponManagement.faceValue" label="面值" align="center"> </el-table-column>
          <el-table-column prop="collectionTime" label="领取时间" align="center"> 
            <template slot-scope="scope">
              <span>{{ timeTrans(scope.row.collectionTime, 1) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="useTime" label="使用时间" align="center"> 
            <template slot-scope="scope">
              <span>{{ timeTrans(scope.row.useTime, 1) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="useOrder" label="使用订单" align="center"> </el-table-column>
          <el-table-column prop="user.userName" label="使用账户" align="center"> </el-table-column>
          <el-table-column prop="phone" label="联系方式" align="center"> </el-table-column>
        </el-table>
        <!-- 页码 -->
        <el-pagination
          class="msg-pagination-container"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="count"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :background="true"
        >
        </el-pagination>
      </div>
    </div>
  </template>
  
  <script>
  import time from "../utils/time";
  export default {
    mixins: [time],
    data: function () {
      return {
        currentPage4: 1,
        options: [
          {
            value: '0',
            label: '发放中',
          },
          {
            value: '1',
            label: '已结束',
          },
        ],

        couponName:'',
        phone:"",
        page: 1,
        count: 5,
        total: 1,


        form: { status: '', date: '' },
        tableData: [],
        timeValue:[],
      };
    },
    methods: {
      // 查询
      onSearch: function () {
        this.$axios({
          url: "/smart/coupon-use/search",
          method: "post",
          params:{
            pageNum:this.page,
            pageSize:this.count,
            collectionTime: this.timeValue[0],
            collectionTime: this.timeValue[1],
          },
          data:{
            couponName:this.couponName,
            phone:this.phone,
            
          },
        }).then(({ data }) => {
          console.log(data);
          if (data.code == "00000") {
            this.tableData = data.data.pageInfo.list;
            this.total = data.data.pageInfo.total;
          } else {
            this.$message.error("数据加载失败！");
          }
        });
      },
      onReset: function () {
        this.timeValue = [];
        this.couponName = "";
        this.phone = "";
        this.getData();
      },
      detail: function (row) {
        // console.log(row, detail);
      },
      finish: function (row) {
        // console.log(row, finish);
      },


      handleSizeChange(val) {
        this.count = val;
        this.getData();
        // console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getData();
        // console.log(`当前页: ${val}`);
      },

      // 数据链接
      getData:function(){
        this.$axios({
        url:'/smart/coupon-use/list' + "/" + this.page + "/" + this.count,  //get请求
        method:'GET',
        // params:{
        //   page:this.page,
        //   count:this.count,
        // }
      }).then(({data})=>{
        console.log(data);
        if(data.code == "00000"){
          this.tableData = data.data.pageInfo.list;
          this.total = data.data.pageInfo.total;
        }else{
          this.$message.error('数据加载失败！')
        }
      });
      }
    },
    mounted:function(){
      this.getData();
    },
  };
  </script>
  
  <style lang="less" scoped>
  .container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    .container-title {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      p {
        color: #333333;
        font-size: 16px;
        font-weight: 400;
        font-family: 'Arial Normal', 'Arial';
      }
      .el-breadcrumb-item {
        color: rgba(148, 148, 148, 0.898039215686275);
        font-size: 12px;
        font-weight: 400;
        font-family: 'Arial Normal', 'Arial';
      }
    }
    .search-box {
      width: 98%;
      height: 80px;
      background: #ffffff;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      border: 1px solid #ffffff;
      border-radius: 5px;
      .el-form {
        width: 100%;
        background: #ffffff;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        .el-form-item {
          margin-bottom: 0;
          .el-input{
              width: 150px;
              margin-left: 10px
          }
          .el-select {
            width: 150px;
            margin-left: 10px;
          }
          .Time {
            margin-left: 10px;
          }
          .refer {
            margin-left: 10px;
          }
          .reset {
            background-color: white;
            color: #c0c4cc;
            border: 1px solid #c0c4cc;
          }
          .reset:hover {
            color: #0bb197;
          }
        }
        .el-date-editor--datetimerange.el-input__inner {
          width: 310px;
        }
      }
    }
    .data-list {
      width: 98%;
      height: 100%;
      background: #ffffff;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-around;
      margin-top: 20px;
      .data-list-title {
        width: 98%;
        height: 60px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        span {
          height: 16px;
          font-family: 'Arial Normal', 'Arial';
          font-weight: 700;
          font-style: normal;
          font-size: 13px;
          color: #3c4145;
        }
      }
      .el-table {
        flex: 1;
        .el-button {
          color: #0bb197;
        }
      }
      .el-pagination {
        width: 98%;
        height: 60px;
        display: flex;
        justify-content: flex-end;
        align-items: center;
      }
    }
  }
  </style>
  <style>
  .el-pagination.is-background .el-pager li:not(.disabled):hover {
    color: #0bb197;
  }
  .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #0bb197;
    color: #fff;
  }
  </style>